package com.controller;

import com.entity.Girl;
import com.repository.BoyRepository;
import com.service.SocketClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/girl")
public class GirlController {
    @Autowired
    private BoyRepository boyRepository;

    @GetMapping("/add")
    @Transactional(rollbackFor = Exception.class)
    public String add(){
        try {
            String name = (char) (0x4e00 + (int) (Math.random() * (0x9fa5 - 0x4e00 + 1))) + "";
            Girl boy = new Girl();
            boy.setName(name);
            boyRepository.save(boy);
            return "ok";
        }catch (Exception e){
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }
}
